package com.petalsgroup.petals.service.admin.impl;

import com.petalsgroup.petals.dao.admin.AdminDao;
import com.petalsgroup.petals.dao.admin.impl.AdminDaoImpl;
import com.petalsgroup.petals.pojo.CommentsDO;
import com.petalsgroup.petals.service.admin.CommentAdminService;
import com.petalsgroup.petals.util.LimitUtil;

import java.util.List;

public class CommentAdminServiceIpml implements CommentAdminService {
    AdminDao ad=new AdminDaoImpl();

    /**
     * 分页获取评论信息
     * @param commentAdminLimit
     * @author wgd
     * @return
     */
    @Override
    public List<CommentsDO> findAllCommentByPages(LimitUtil commentAdminLimit) {
        long len = ad.countComment();
        if (len == 0) {
            return null;
        }
        if (commentAdminLimit.getCurrentPage()==null){
            commentAdminLimit.init(len, 4, 1);
        }
        List<CommentsDO> commentList = ad.listComment(commentAdminLimit.getSelect(), commentAdminLimit.getNum());
        if (commentList == null) {
            return null;
        }
        return commentList;
    }
    /**
     * 获取评论信息
     * @return
     * @author wgd
     */
    @Override
    public List<CommentsDO> findAllComment() {
        List<CommentsDO> list = ad.selectAllComment();
        return list;
    }

    /**
     * 删除某条评论
     * @param com_id
     * @author wgd
     */

    @Override
    public void deleteComment(String com_id) {
        ad.deleteCommentById(com_id);

    }

    /**
     * 根据选择的评论id来删除评论
     * @param com_ids
     * @author wgd
     */
    @Override
    public void deleteSelectComment(String[] com_ids) {
        if (com_ids != null && com_ids.length>0){
            for (String com_id:com_ids){
                ad.deleteCommentById(com_id);
            }
        }
    }

    /**
     * 通过用户id来查询评论
     * @param userId
     * @return
     * @author wgd
     */
    @Override
    public List<CommentsDO> findCommentByUserId(String userId) {
        List<CommentsDO> list=ad.findCommentByUserId(userId);
        return list;
    }

    /**
     * 通过动漫id来查询评论
     * @param adminId
     * @return
     * @author wgd
     */
    @Override
    public List<CommentsDO> findCommentByAdminId(String adminId) {
        List<CommentsDO> list=ad.findCommentByAdminId(adminId);
        return list;
    }

    /**
     * 通过时间段找评论
     * @param timeQuantum
     * @return
     * @author wgd
     */
    @Override
    public List<CommentsDO> findCommentByTimeQuantum(String timeQuantum) {
        List<CommentsDO> list=ad.findCommentByTimeQuantum(timeQuantum);
        return list;
    }

    /**
     * 通过点赞人数老找出最高的几条评论
     * @param number
     * @return
     */
    @Override
    public List<CommentsDO> findTopCommentByLikeNum(String number) {
        List<CommentsDO> commentList=ad.findTopCommentByLikeNum(number);
        if (commentList == null) {
            return null;
        }
        return commentList;
    }
}
